package com.creditease.rss.ui.adapter;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.creditease.rss.model.RssModel;
import com.creditease.rss.ui.R;

public class RssAdapter extends BaseAdapter {

	private static final String TAG = RssAdapter.class.getSimpleName();

	private Context context;

	private List<RssModel> list;
	
	

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public RssAdapter(Context context, List<RssModel> list) {
		super();
		this.context = context;
		this.list = list;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		convertView = LayoutInflater.from(context).inflate(R.layout.home_item, null);
		RssModel itemModel = list.get(position);
		ImageView logo = (ImageView) convertView.findViewById(R.id.rss_logo);
		TextView title = (TextView) convertView.findViewById(R.id.rss_title);
		TextView desc = (TextView) convertView.findViewById(R.id.rss_desc);

		
		title.setText(itemModel.title);
		desc.setText(itemModel.desc);
		//Log.d(TAG, "isRead="+itemModel.isRead);
		if(itemModel.isRead){
			//title.setTextColor(R.color.itemlist_article_read);
			logo.setImageResource(R.drawable.icon_rss_read);
		}else {
			//title.setTextColor(R.color.main_title_color);
			logo.setImageResource(R.drawable.icon_rss);
		}
		return convertView;
	}

}
